package com.yeepay.demo;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.epos.facade.EposFacade;

/**
 * 
 * <p> EPOS测试用消费</p>
 * @Title: EposPayUtill.java
 * @Projectname: yeepaytest
 * @Package: com.yeepay.epos 
 * @Copyright: Copyright (c)2014
 * @Company: YeePay
 * @version: 1.0
 * @Create: 2014年3月9日
 */
public class EposDemo {
	private static final Log log = LogFactory.getLog(EposDemo.class);
	
	
	public static String EPOSSALE_TYPE="EposSale";
	public static String EPOSREQUESTURL="https://www.yeepay.com/app-merchant-proxy/command";
	public static String CUSTOMER_NUMBER="10011206975";
	public static String CUSTOMER_KEY="M6N9DW05r1iCZ07wNdfo40s6GD8469626zPouz136NKm4g1271fs63604271";
	
	
	/**
	 * 
	 * <p>消费</p>
	 * @Title eposSale
	 * @throws Exception
	 * @return void 
	 * @Create 2014年4月2日
	 */
	public static void eposSale() throws Exception{
		log.info("-------------------------消费-------------------------");
		String p0_Cmd = "EposSale";
		String p2_Order = "4040118240056";//"test001";
		String p3_Amt="0.10";
		String p4_Cur="CNY";
		String p5_Pid="flight";
		String p8_Url="http://cjqhut.6655.la:25844/YeepayDemo/ServletPayResult";
		String pa_CredType="IDCARD";
		String pb_CredCode="362334198911112813";//"370523198804260038";
		String pd_FrpId = "BOCOCREDIT";
		String pe_BuyerTel="13716372979";//"15215317596";
		String pf_BuyerName="程建强";
		String pt_ActId="4581230922953684";//"4062522900966872";
		String pa2_ExpireYear="2019";//"2020";;
		String pa3_ExpireMonth="12";//"12";
		String pa4_CVV="805";//"973";
		String prisk_TerminalCode="";
//		String prisk_Param = "{\"industry\":\"4511\",\"air_IsMember\":\"1\",\"air_ApplicationMode\":\"B2C\",\"air_Phone\":\"15215317596\","
//				+ "\"air_ContactPhone\":\"15215317596\",\"air_ContactName\":\"张三\",\"air_Flight\":[{\"air_FlightNo\":\"MU5102\",\"air_Cabin\":"
//				+ "\"N\",\"air_STime\":\"20140402080000\",\"air_ETime\":\"20140402101000\",\"air_SCity\":\"PEK\",\"air_ECity\":\"SHA\"}],"
//				+ "\"air_Passenger\":[{\"air_Name\":\"李强\",\"air_CertificateType\":\"OTHER\",\"air_CertificateNo\":\"11111111\",\"air_Email\":"
//				+ "\"\",\"air_FlightNo\":\"MU5102\",\"air_STime\":\"20140402080000\",\"air_Phone\":\"\",\"air_Pnr\":\"\",\"air_TicketNo\":\"\","
//				+ "\"air_Type\":\"00\"}]}";
		String pr_NeedResponse="1";
		
		Map<String,String> hm=new HashMap<String,String>();	
		hm.put("p0_Cmd",p0_Cmd);////业务类型
		hm.put("p2_Order",p2_Order);//商户订单号
		hm.put("p3_Amt",p3_Amt);//消费金额
		hm.put("p4_Cur",p4_Cur);//交易币种
		hm.put("p5_Pid",p5_Pid);//商品名称
		hm.put("p8_Url",p8_Url);//接收支付结果地址
		hm.put("pa_CredType",pa_CredType);//证件类型
		hm.put("pb_CredCode",pb_CredCode);//证件号码
		hm.put("pd_FrpId",pd_FrpId);//银行编码
		hm.put("pe_BuyerTel",pe_BuyerTel);//消费者手机号
		hm.put("pf_BuyerName",pf_BuyerName);//消费者姓名	
		hm.put("pt_ActId",pt_ActId);//信用卡卡号
		hm.put("pa2_ExpireYear",pa2_ExpireYear);//有效期（年）
		hm.put("pa3_ExpireMonth",pa3_ExpireMonth);//有效期（月）
		hm.put("pa4_CVV",pa4_CVV);//CVV
		hm.put("prisk_TerminalCode", prisk_TerminalCode);//终端号
//		hm.put("prisk_Param", prisk_Param);//风控扩展参数
		hm.put("pr_NeedResponse",pr_NeedResponse);//需要应答
		
		Map<String,String>  result = EposFacade.trxRequest(EPOSREQUESTURL, CUSTOMER_NUMBER, CUSTOMER_KEY, hm,"POST", "gbk");
		log.info(result);
	}
	
	/**
	 * 
	 * <p>验证码消费接口</p>
	 * @Title eposVerifySale
	 * @throws Exception
	 * @return void 
	 * @author shihj
	 * @Create 2014年4月2日
	 */
	public static void eposVerifySale() throws Exception{
		log.info("-------------------------验证码消费-------------------------");
		String p0_Cmd = "EposVerifySale";
		String p2_Order = "4040118240056";//"test001";
		String pb_VerifyCode="927";
		
		Map<String,String> hm=new HashMap<String,String>();	
		hm.put("p0_Cmd",p0_Cmd);////业务类型
		hm.put("p2_Order",p2_Order);//商户订单号
		hm.put("pb_VerifyCode",pb_VerifyCode);//验证码
		
		Map<String,String>  result = EposFacade.trxRequest(EPOSREQUESTURL, CUSTOMER_NUMBER, CUSTOMER_KEY, hm,"POST", "gbk");
		log.info(result);
	}
	
	/**
	 * 
	 * <p>验证码获取接口</p>
	 * @Title eposVerifySale
	 * @throws Exception
	 * @return void 
	 * @author shihj
	 * @Create 2014年4月2日
	 */
	public static void EposVerifyCodeReceive() throws Exception{
		log.info("-------------------------验证码获取-------------------------");
		String p0_Cmd = "EposVerifyCodeReceive";
		String p2_Order = "404011824001";//"test001";
		
		Map<String,String> hm=new HashMap<String,String>();	
		hm.put("p0_Cmd",p0_Cmd);////业务类型
		hm.put("p2_Order",p2_Order);//商户订单号
		
		Map<String,String>  result = EposFacade.trxRequest(hm, "POST", "gbk");
		log.info(result);
	}
	
	/**
	 * 
	 * <p>查询</p>
	 * @Title QueryOrdDetail
	 * @throws Exception
	 * @return void 
	 * @author shihj
	 * @Create 2014年4月2日
	 */
	public static void QueryOrdDetail() throws Exception{
		log.info("-------------------------查询-------------------------");
		String p0_Cmd = "QueryOrdDetail";
		String p2_Order = "404011824001";//"test001";
		String pv_Ver = "";//"test001";
		String p3_ServiceType = "";//"test001";
		
		Map<String,String> hm=new HashMap<String,String>();	
		hm.put("p0_Cmd",p0_Cmd);////业务类型
		hm.put("p2_Order",p2_Order);//商户订单号
		hm.put("pv_Ver",pv_Ver);//版本号
		hm.put("p3_ServiceType",p3_ServiceType);//查询类型
		
		Map<String,String>  result = EposFacade.trxRequest(hm, "POST", "gbk");
		log.info(result);
	}
	
	public static void RefundOrd() throws Exception{
		log.info("-------------------------退款-----------------------");
		String p0_Cmd = "RefundOrd";
		String p2_Order = "404011824001";//"test001";
		String pb_TrxId = "404011824001I";
		String p3_Amt = "0.01";
		String p4_Cur="CNY";
		String p5_Desc = "退款原因的信息";
		String pv_Ver="";
		
		Map<String,String> hm=new HashMap<String,String>();	
		hm.put("p0_Cmd",p0_Cmd);////业务类型
		hm.put("p2_Order",p2_Order);//退款请求号
		hm.put("pb_TrxId",pb_TrxId);//易宝支付交易流水号
		hm.put("p3_Amt",p3_Amt);//退款金额
		hm.put("p4_Cur",p4_Cur);//交易币种
		hm.put("p5_Desc",p5_Desc);//退款说明
		hm.put("pv_Ver",pv_Ver);//版本号
		
		Map<String,String>  result = EposFacade.trxRequest(hm, "POST", "gbk");
		log.info(result);
	}
	
	
	public static void EposRevocation() throws Exception{
		log.info("-------------------------撤销-----------------------");
		String p0_Cmd = "EposRevocationOrd";
		String p2_Order = "404011824001";//"test001";
		String pb_TrxId = "404011824001I";
		String pv_Ver="";
		
		Map<String,String> hm=new HashMap<String,String>();	
		hm.put("p0_Cmd",p0_Cmd);////业务类型
		hm.put("p2_Order",p2_Order);//撤销请求号
		hm.put("pb_TrxId",pb_TrxId);//易宝支付交易流水号
		hm.put("pv_Ver",pv_Ver);//版本号
		
		Map<String,String>  result = EposFacade.trxRequest(hm, "POST", "gbk");
		log.info(result);
	}
	
	public static void callbackDeal() throws Exception{
		log.info("-------------------------回调处理-----------------------");
		String str = "p1_MerId=10001126856&r0_Cmd=EposFailed&r1_Code=-100&r2_TrxId=315222276759332I&r3_Amt=0.1&r6_Order=404011824001&rp_TrxDate=20140402180007&rp_Msg=%D6%A7%B8%B6%D0%C5%CF%A2%B4%ED%CE%F3&hmac=913ef8579f672c2ad52bfbe9b407a475";
		Map<String,String>  result = EposFacade.callbackDeal(str);
		log.info(result);
	}
	
	public static void callbackBuy() throws Exception{
		log.info("-------------------------回调处理-----------------------");
		String str = "p1_MerId=10001126856&r0_Cmd=Buy&r1_Code=1&r2_TrxId=818141048462242E&r3_Amt=0.1&r4_Cur=RMB&r5_Pid=&r6_Order=201404161000249272&r7_Uid=&r8_MP=&r9_BType=2&ru_Trxtime=20140416112637&ro_BankOrderId=019206&rb_BankId=CCBCREDIT-NET&rp_PayDate=20140416104438&rq_CardNo=&rq_SourceFee=0.0&rq_TargetFee=0.0&hmac=e7f704be31be20fc6a6cafd2b73adabd";
		Map<String,String>  result = EposFacade.callbackDeal(str);
		log.info(result);
	}
	
	
	public static void main(String[] args) throws Exception {
//			eposSale();
			eposVerifySale();
//			EposVerifyCodeReceive();
//			QueryOrdDetail();
//			EposRevocation();
//			RefundOrd();
//			callbackDeal();
//			callbackBuy();

	}
}
